package com.eascs.dubbo.api.internal;

import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.dubbo.config.annotation.Service;
import com.eascs.admin.api.internal.ChannelService;
import com.eascs.admin.o2o.loan.entity.O2oLoanBkInfo;
import com.eascs.admin.o2o.loan.entity.O2oLoanGsInfo;
import com.eascs.admin.o2o.loan.entity.O2oLoanScInfo;
import com.eascs.admin.o2o.loan.service.O2oLoanBkService;
import com.eascs.admin.o2o.loan.service.O2oLoanGsService;
import com.eascs.admin.o2o.loan.service.O2oLoanScService;
import com.eascs.common.util.StringUtil;

@Service
public class ChannelServiceImpl implements ChannelService{

	@Autowired
	O2oLoanGsService gsService;
	
	@Autowired
	O2oLoanScService scService;
	
	@Autowired
	O2oLoanBkService o2oLoanBkService;
	
	
	@Override
	public String UpdateSGChannel(O2oLoanGsInfo t) {
		O2oLoanGsInfo gsInfo = gsService.getLoanapplyNo(t.getLoanapplyNo());
		if (null == t.getStartOperateTime()) {
			return "本市场经营开始时间不能为空";
		}
		if (StringUtil.isBlank(t.getIsParking())) {
			return "档口有无车位不能为空";
		}
		if (null != gsInfo) {
			gsInfo.setStartOperateTime(t.getStartOperateTime());
			gsInfo.setIsParking(t.getIsParking());
			gsService.updateEntity(gsInfo);
		}else
			gsService.insertEntity(t);
		return null;
	}


	@Override
	public String UpdateSCChannel(O2oLoanScInfo t) {
		O2oLoanScInfo gsInfo = scService.getLoanapplyNo(t.getLoanapplyNo());
		if (null == t.getWhitelistTime()) {
			return "与白名单内商超合作开始时间不能为空";
		}
		if (null != gsInfo) {
			gsInfo.setWhitelistTime(t.getWhitelistTime());
			scService.updateEntity(gsInfo);
		} else
			scService.insertEntity(t);
		return null;
	}


	@Override
	public String UpdateBPJChannel(O2oLoanBkInfo loanBkInfo) {
		if (StringUtil.isBlank(loanBkInfo.getProductName())) {
			return "与渠道企业采购的产品不能为空";
		}
		if (null == loanBkInfo.getMonthPrice()) {
			return "月均合作额不能为空";
		}
		if (null == loanBkInfo.getStartCoopDate()) {
			return "与渠道企业合作起始时间";
		}
		if (StringUtil.isBlank(loanBkInfo.getId())) {
			o2oLoanBkService.insertEntity(loanBkInfo);
		} else {
			O2oLoanBkInfo bkInfo = o2oLoanBkService.getEntityById(loanBkInfo.getId());
			bkInfo.setMonthPrice(loanBkInfo.getMonthPrice());
			bkInfo.setProductName(loanBkInfo.getProductName());
			bkInfo.setStartCoopDate(loanBkInfo.getStartCoopDate());
			o2oLoanBkService.updateEntity(bkInfo);
		}
		return null;
	}

}
